package com.example.xunai.dto.response.conversation;

import com.example.xunai.entity.Conversation;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ConversationResponse {
    private Long id;
    private String title;
    private String model;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;
    private Integer messageCount;
    private Integer totalTokens;
    private String sessionId;
    private Long userId;

    public static ConversationResponse fromEntity(Conversation conversation) {
        return ConversationResponse.builder()
                .id(conversation.getId())
                .title(conversation.getTitle())
                .model(conversation.getModel())
                .createTime(conversation.getCreateTime())
                .updateTime(conversation.getUpdateTime())
                .sessionId(conversation.getSessionId())
                .userId(conversation.getUserId())
                .build();
    }

    public static ConversationResponse fromEntity(Conversation conversation, Integer messageCount, Integer totalTokens) {
        return ConversationResponse.builder()
                .id(conversation.getId())
                .title(conversation.getTitle())
                .model(conversation.getModel())
                .createTime(conversation.getCreateTime())
                .updateTime(conversation.getUpdateTime())
                .sessionId(conversation.getSessionId())
                .userId(conversation.getUserId())
                .messageCount(messageCount)
                .totalTokens(totalTokens)
                .build();
    }
}